<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link
	href="${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/css/authority.css"
	rel="stylesheet" type="text/css">
<title>添加角色</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/validate.js">
</script>
</head>
<body>
</body>
</html>
<script>

Ext.onReady(function(){

	Ext.QuickTips.init();  
	<%@ include file="jsp/general.jsp"%>
    //------------------------------------------------------------------------
	//添加角色的表单
	//
	//--------------------------------------------------------------------------
	var addRole = new Ext.FormPanel({
	    labelWidth: 75,
	    id:'addRole',
	    frame:true,
	    title: '添加角色',
	    bodyStyle:'padding:5px 5px 0',
	    width: 350,
	    defaults: {width: 230},
	    defaultType: 'textfield',
	    items: [{
	            fieldLabel: '角色名称',
	            name: 'role_name',
	            id: 'role_name',
	            maxLength:10,
	            allowBlank:false,
	            blankText:'角色名称不可为空',
	            vtype: 'isNumberAlphaUnderlineChinese'
	        },{
	        	xtype:'textarea',
	            fieldLabel: '描述',
	            name: 'role_descn',
	            id: 'role_descn',
	            //maxLength:50,
	            vtype: 'isNumberAlphaUnderlineChineseSpaceMaxLength200'
	        } 
	    ]
	});
	//---------------------------------------------------------------------------
	//添加角色
	//
	//---------------------------------------------------------------------------
//	 if(!win){
	 var win = new Ext.Window({
            layout: 'fit',
            width : 380,
            height: 200,
            plain : true,
            animEl: 'result',
            closable: false,
            items: [addRole],
            buttons: [{
               text     : '添加',
               handler  : function(){
                   	if(addRole.form.isValid()){
                   		addRole.form.submit({
	                		url: '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/roleModule/roleAction/InsertRole.action', 
	                		success : function(form, action) {
	                			var myResult = Ext.util.JSON.decode(action.response.responseText);
	                			if (myResult.success == 'true') {
	                				if(myResult.result > 0){
	                					Ext.MessageBox.show({
	                				 		title: '添加成功',
		                                    msg: '恭喜您，添加角色成功！',
		                                    width:200,
		                                    buttons: Ext.MessageBox.OK,
		                                    fn: function(btn) {
										         window.location = '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/roleModule/rolePage/roleList.jsp';
										    }
		                                 });                                    
									  } else {
											  	Ext.MessageBox.show({
				                                    title: '添加失败',
				                                    msg: '对不起，该角色已经存在！',
				                                    buttons: Ext.MessageBox.OK,
				                                    icon: Ext.MessageBox.ERROR
			                                	});
									  }  
	                            } else {
		                            	Ext.MessageBox.show({
		                                    title: '添加失败',
		                                    msg: '对不起，添加角色失败！',
		                                    buttons: Ext.MessageBox.OK,
		                                    icon: Ext.MessageBox.ERROR
	                                	});
	                            }
	                        },
	                        failure : function(form, action) {
	                        	
	                        	Ext.MessageBox.show({
                                    title: '添加失败',
                                    msg: '对不起，添加角色失败！',
                                    buttons: Ext.MessageBox.OK,
                                    icon: Ext.MessageBox.ERROR
                                });
	                        },
	                		waitMsg:'正在添加角色，请稍后...'
                		});
                   	} else {
                   		Ext.MessageBox.alert('警告','对不起，您的信息有误！')
                   	}
                 }
            },{
                text     : '返回',
                handler  : function(){
                	//window.history.back();
                    //win.hide();
                    window.location = 'roleList.jsp';
                    }
           },{
                text     : '重置',
                handler  : function(){
                    addRole.form.reset(); 
                }
            }]
        });
//     }
    win.show();
    document.getElementById('role_name').maxLength = 10;
});


</script>